package cn.wit.summit.chwan.ui.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.wit.summit.chwan.R;
import cn.wit.summit.chwan.adapters.FragmentPagerAdapter;

/**
 * Created by Alan on 2018/4/11.
 */

public class MakeMoneyFragment extends Fragment {
    @Bind(R.id.makeMoneyTabs)
    SlidingTabLayout makeMoneyTabs;
    @Bind(R.id.makeMoneyViewPager)
    ViewPager makeMoneyViewPager;

    private String TAG = "MakeMoneyFragment";

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_make_money, container, false);
        ButterKnife.bind(this, view);

        initTabView();
        return view;
    }

    private void initTabView() {
        List<FragmentPagerAdapter.Item> items = new ArrayList<>();
        items.add(new FragmentPagerAdapter.Item("推荐", MakeMoneyRecommendFragment.newInstance()));
        items.add(new FragmentPagerAdapter.Item("排行", MakeMoneyRankingFragment.newInstance(0)));

        FragmentPagerAdapter adapter = new FragmentPagerAdapter(getActivity().getSupportFragmentManager(), items);
        makeMoneyViewPager.setAdapter(adapter);
        makeMoneyViewPager.setCurrentItem(0);
        makeMoneyViewPager.setOffscreenPageLimit(2);
        makeMoneyTabs.setViewPager(makeMoneyViewPager);
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (!hidden) {
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
